<template>
    <header class="main-header">
      <!-- Logo -->
      <a href="index2.html" class="logo">
        <!-- mini logo for sidebar mini 50x50 pixels -->
        <span class="logo-mini"></span>
        <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><img style="width: 100px;" src="@/assets/LOGO-19.jpg" alt=""></span>
      </a>
      <!-- Header Navbar: style can be found in header.less -->
      <nav class="navbar navbar-static-top">
        <!-- Sidebar toggle button-->
        <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
          <span class="sr-only">Toggle navigation</span>
        </a>
        <div class="">
          <ul class="nav navbar-nav">
            <li class="dropdown messages-menu" v-for="(item,index) in topMenus" :class="{'active': index == menusIndex}">
              <a :href="item.url" @click="topMenuClick(item.id,index)" class="dropdown-toggle" data-toggle="dropdown">
                {{item.title}}
              </a>
            </li>
          </ul>
        </div>
        <Login-User></Login-User>
      </nav>
    </header>
</template>

<script>
  import LoginUser from '@/components/common/LoginUser'
  import {setCookie,getCookie} from "../../js/common/util";
  export default {
    name: "Header",
    props:["topMenus"],
    data() {
      return {
        items: [],
        menusIndex:0
      }
    },
    components: {
      LoginUser
    },
    methods: {
      menusInfo: function () {
        // this.menus = this.levelOne;
        // console.log(vm.menus)
      },

      /**
       * 一级菜单点击事件
       * @param _menuId 菜单ID
       */
      topMenuClick:function(_menuId,index) {
        //调用父组件(home.vue)中getChildrenByTopMenuId方法
        setCookie("index",index);
        this.menusIndex = getCookie("index");
        this.$emit("getChildrenByTopMenuId", _menuId,index);
        setCookie("menuId", _menuId);
      },
      created() {
        this.$nextTick(function () {
          this.menusInfo();
          this.topMenuClick(getCookie("menuId"),getCookie("index"))
        })
      },
    }
  }
</script>

<style scoped>

</style>
